﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ShopMobile_App
{
    public partial class frmCart : Form
    {
        public frmCart()
        {
            InitializeComponent();
            comboBoxStatus.Items.Add("Tất cả");
            comboBoxStatus.Items.Add("Chưa giao");
            comboBoxStatus.Items.Add("Đã giao");
            comboBoxStatus.Items.Add("Hủy đơn hàng");
        }
        
        private void frmCart_Load(object sender, EventArgs e)
        {
            CartsBLL c = new CartsBLL();
            dataGridViewCarts.DataSource = c.getCartStt(comboBoxStatus.Text);
        }

        private void comboBoxStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            CartsBLL cat = new CartsBLL();
            dataGridViewCarts.DataSource = cat.getCartStt(comboBoxStatus.SelectedText.ToString());
            //dataGridViewCart_Items.Refresh();
            frmCart_Load(sender, e);
            dataGridViewCarts.Refresh();
        }

        private void dataGridViewCarts_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow curRow = dataGridViewCarts.CurrentRow;
            txtName.Text = curRow.Cells[4].Value.ToString();
            txtAddress.Text = curRow.Cells[6].Value.ToString();
            txtPhoneNumber.Text = curRow.Cells[8].Value.ToString();
            txtSumCash.Text = curRow.Cells[9].Value.ToString();
            txtDate.Text = curRow.Cells[1].Value.ToString();
            comboBoxStt2.Text = curRow.Cells[2].Value.ToString();
            txtIDCart.Text = curRow.Cells[0].Value.ToString();
            //txtNameCat.Text = curRow.Cells[1].Value.ToString();
            Cart_itemBLL cat_it = new Cart_itemBLL();
            dataGridViewCart_Items.DataSource = cat_it.getCartItems(int.Parse(txtIDCart.Text));

        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            DataGridViewRow curRow = dataGridViewCarts.CurrentRow;
            CartsBLL cat = new CartsBLL();
            int stt;
            if (comboBoxStt2.SelectedIndex ==1)
            {
               stt = 1;
            }
            else
            {
                stt = comboBoxStt2.SelectedIndex;
            }
            cat.setStatusCart(int.Parse(txtIDCart.Text), stt);
            frmCart_Load(sender, e);
            dataGridViewCarts.Refresh();
        }

    }
}
